package org.chench.extra.logsift.config;

import org.chench.extra.logsift.config.properties.AppProperties;
import org.chench.extra.logsift.service.LogMonitor;
import org.chench.extra.logsift.service.impl.LogHandlerContext;
import org.chench.extra.logsift.service.impl.LogMonitorImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 应用全局配置
 * @author chench
 * @date 2025.05.17
 */
@Configuration
public class AppConfig {
    @Bean
    public LogMonitor logMonitor(AppProperties appProperties, LogHandlerContext logHandlerContext) {
        Path pointerFilePath = Paths.get(appProperties.getPointerFilePath());
        LogMonitor logMonitor = new LogMonitorImpl(pointerFilePath, appProperties.getLogAppMap());
        logMonitor.setLogHandler(logHandlerContext);
        return logMonitor;
    }
}
